package cn.buk.tms.eotms.controller;

import cn.buk.tms.eotms.dto.AccessTokenDto;
import cn.buk.tms.eotms.service.EnterpriseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import jakarta.servlet.http.HttpServletRequest;

/**
 * @author yfdai
 */
@RestController
public class TokenController extends BaseController {

  private EnterpriseService enterpriseService;

  @Autowired
  public TokenController(EnterpriseService enterpriseService) {
    this.enterpriseService = enterpriseService;
  }

  /**
   * 获取access token
   * @param request
   * @param grantType 授权类型
   * @param appId 第三方应用唯一id
   * @param appSecret 第三方应用唯一密钥
   * @return
   */
  @PostMapping("/token")
  public AccessTokenDto getAccessToken(HttpServletRequest request,
                                       @RequestParam("grant_type") String grantType,
                                       @RequestParam("appid") String appId,
                                       @RequestParam("secret") String appSecret) {

    return enterpriseService.getAccessToken(grantType, appId, appSecret);
  }

}
